public class Leetcode3142 {
    public static void main(String[] args) {
        int[][] grid=new int[][]{{1,0,2},{1,0,2}};
        boolean res=satisfiesConditions(grid);
        System.out.println(res);
    }

    public static boolean satisfiesConditions(int[][] grid) {
        int lastRow=grid.length;
        int lastCol=grid[0].length;
        for(int i=0;i<grid.length;i++){
            for(int j=0;j<grid[0].length;j++){
                //如果不是最后一行
                if(lastRow-1!=i){
                    if(grid[i][j]!=grid[i + 1][j]){
                        return false;
                    }
                }
                //如果不是最后一列
                if(lastCol-1!=j){
                    if(grid[i][j] == grid[i][j + 1]){
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
